package com.cb.controller.bak.order;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.cb.core.controller.BaseFormController;
import com.cb.domain.model.order.OrderLog;
import com.cb.domain.service.order.OrderLogManager;

/**
 * 
 * @Author author name
 * Create Time:
 * <p>Class Description Here [TODO]</p>
 */
public class OrderLogFormController extends BaseFormController {
	
	@Autowired
	private OrderLogManager orderLogManager=null;
	
	public OrderLogFormController() {
		 setCommandName("orderLog");
	     setCommandClass(OrderLog.class);
	}
	
	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		
		OrderLog orderLog=(OrderLog)command;
		String msg=null;
		//validate the logic business data here [TODO]
		if(orderLog.getId()==null){
			msg=getText("orderLog.added",orderLog.getId());
		}else{
			msg=getText("orderLog.updated",orderLog.getId());
		}
		
		orderLogManager.save(orderLog);
		
		saveMessage(request,msg);
		
		return new ModelAndView(getSuccessView());
	}
	
	@Override
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		OrderLog orderLog=null;
		String id=request.getParameter("id");
		if(StringUtils.isNotEmpty(id)){
			orderLog=orderLogManager.get(new Long(id));
		}else{
			orderLog=new OrderLog();
		}
		return orderLog;
	}
	
}
